#ifndef _HSTR_H
#define _HSTR_H

#include <lib/hash.h>
#include <string.h>
#include <compiler.h>

typedef struct hash_string {
    u32 hash;
    size_t len;
    char* val;
} hstr_t;

#define HSTR(str, length)                                   \
    (hstr_t)                                                \
    {                                                       \
        .len = (length), .val = (str)                       \
    }

#define HHSTR(str, length, strhash)                         \
    (hstr_t)                                                \
    {                                                       \
        .len = (length), .val = (str), .hash = (strhash)    \
    }

#define HSTR_EQ(hstr_p1, hstr_p2) ((hstr_p1)->hash == (hstr_p2)->hash)

static inline void hstr_rehash(hstr_t* hash_str) {
    hash_str->hash = strhash32(hash_str->val);
}

static inline void hstr_copy(hstr_t* dst, hstr_t* src) {
    strcpy(dst->val, src->val);
    dst->hash = src->hash;
    dst->len = src->len;
}

#endif /* _HSTR_H */